package cn.topevery.garden.wapi.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * 描述 日期工具类
 *
 * @author wenzhao.lin
 * @created 2021 -03-26 10:13:34
 */
public class DateUtils {

    /**
     * 描述 获取今日起始时间.
     *
     * @return the today start time
     * @author wenzhao.lin
     * @created 2021 -03-26 10:13:34
     */
    public static Date getTodayStartTime() {
        Calendar startTime = Calendar.getInstance();
        startTime.set(Calendar.HOUR,0);
        startTime.set(Calendar.MINUTE,0);
        startTime.set(Calendar.SECOND,0);
        startTime.set(Calendar.MILLISECOND,0);
        return startTime.getTime();
    }


    /**
     * 描述 获取今日结束时间
     *
     * @return the today end time
     * @author wenzhao.lin
     * @created 2021 -03-26 10:13:34
     */
    public static Date getTodayEndTime() {
        Calendar endTime = Calendar.getInstance();
        endTime.set(Calendar.HOUR,23);
        endTime.set(Calendar.MINUTE,59);
        endTime.set(Calendar.SECOND,59);
        endTime.set(Calendar.MILLISECOND,999);
        return endTime.getTime();
    }

    /**
     * 描述 获取本年的第一天.
     *
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:30:36 Get curr year first date.
     */
    public static Date getYearFirstDate(){
        Calendar currCal=Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return getCurrYearFirst(currentYear);
    }


    /**
     * 描述 create.
     *
     * @param year the year
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:37:08 Get year first date.
     */
    public static Date getCurrYearFirst(int year){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        Date currYearFirst = calendar.getTime();
        return currYearFirst;
    }

    /**
     * 描述 获取当年的最后一天.
     *
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:30:36 Get curr year last date.
     */
    public static Date getYearLastDate(){
        Calendar currCal=Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return getYearLast(currentYear);
    }

    /**
     * 描述 create.
     *
     * @param year the year
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:37:12 Get year last date.
     */
    public static Date getYearLast(int year){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        calendar.roll(Calendar.DAY_OF_YEAR, -1);
        Date currYearLast = calendar.getTime();
        return currYearLast;
    }

    /**
     * 描述 本月第一天.
     *
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -05-11 13:33:50 Get month last date date.
     */
    public static Date getMonthFirstDate(){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH,1);
        Date currMonthLastDate = calendar.getTime();
        return currMonthLastDate;
    }


    /**
     * 描述 本月最后一天.
     *
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -05-11 13:36:44 Get month last date date.
     */
    public static Date getMonthLastDate(){
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        Date currMonthLastDate = calendar.getTime();
        return currMonthLastDate;
    }

    /**
     * 获取本周的第一天
     *
     * @return String date
     * @author wenzhao.lin
     * @created 2021 -05-11 13:40:02 Get week first date date.
     */
    public static Date getWeekFirstDate(){
        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.WEEK_OF_MONTH, 0);
        cal.set(Calendar.DAY_OF_WEEK, 2);
        Date time=cal.getTime();
        return time;
    }


    /**
     * 描述 获取本周的最后一天.
     *
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -05-11 13:40:02 Get week last date date.
     */
    public static Date getWeekLastDate(){
        Calendar cal=Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
        cal.add(Calendar.DAY_OF_WEEK, 1);
        Date time=cal.getTime();
        return time;
    }

    /**
     * 描述 获取前几天的日期.
     *
     * @return the today start time
     * @author wenzhao.lin
     * @created 2021 -03-26 10:13:34
     */
    public static Date getNearWeekDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
        Date today = calendar.getTime();
        return today;
    }
}
